﻿// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System.Windows;
using System.Windows.Controls;

namespace Coding4Fun.BoxingBots.Boxer.Controls
{
	/// <summary>
	/// Interaction logic for Thumbstick.xaml
	/// </summary>
	public partial class Thumbstick : UserControl
	{
		public Thumbstick()
		{
			InitializeComponent();

			DataContext = this;

			SizeChanged += Thumbstick_SizeChanged;
		}

		void Thumbstick_SizeChanged(object sender, SizeChangedEventArgs e)
		{
			_minMaxValue = OuterCircle.ActualHeight / 2.0;
		}

		double _minMaxValue;

        private void Thumbstick_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            InnerCircleTranslate.X = HorizontalValue * _minMaxValue;
            InnerCircleTranslate.Y = -1 * VerticalValue * _minMaxValue;
        }

        public double HorizontalValue
        {
            get { return (double)GetValue(HorizontalValueProperty); }
            set { SetValue(HorizontalValueProperty, value); }
        }

        // Using a DependencyProperty as the backing store for HorizontalValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HorizontalValueProperty =
            DependencyProperty.Register("HorizontalValue", typeof(double), typeof(Thumbstick), new UIPropertyMetadata(0.0));
        
        public double VerticalValue
        {
            get { return (double)GetValue(VerticalValueProperty); }
            set { SetValue(VerticalValueProperty, value); }
        }

        // Using a DependencyProperty as the backing store for VerticalValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty VerticalValueProperty =
            DependencyProperty.Register("VerticalValue", typeof(double), typeof(Thumbstick), new UIPropertyMetadata(0.0));

	}
}
